<template>
  <!-- 试乘试驾车返利兑换申请维护 -->
  <div>
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle" :labelWidth="110"></TopFilter>

    <FilterTable
      ref="table"
      columnsRef="qjhrebateExchangeApply"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns = columns)"
      :isSelectColumn="false"
    >
      <template slot="controls" slot-scope="props">
        <multiuse-button size="small" type="primary" @click="renderHandle({}, 'add')">新增</multiuse-button>
      </template>
    </FilterTable>

    <Drawer :visible.sync="isShow" :title="drawerTitle" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <SonModel :type="handleType" :rowData="formData" @close="emitCloseHandler" />
    </Drawer>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { queryList, exportExcel } from '@/api/dealerSale/TestDrive/rebateExchangeApply';
import { vehicleConfiguration } from '@/api/omFinance';
import SonModel from './SonModel.vue';

export default {
  name: 'rebateExchangeApply',
  data() {
    this.BaseTable = null;
    this.conf = { add: '新增', edit: '编辑', show: '明细' };

    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: queryList,
      fetchParams: { isDealer: 1, statusList: ['60871001', '60871004'], queryType: 'noRefuse' },
      formData: {},
      isShow: false,
      handleType: '',
      drawerTitle: '',
      exportLoading: false
    };
  },
  mixins: [dictionary],
  components: {
    SonModel
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  created() {
    this.getvehicleList();
  },
  methods: {
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    changeHandle(params) {
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },

    renderHandle(row, type) {
      this.handleType = type;
      this.formData = row;
      this.showHandler();
    },

    showHandler() {
      this.drawerTitle = `${this.conf[this.handleType]}`;
      this.isShow = true;
    },
    emitCloseHandler(val) {
      this.isShow = val;
      this.fetchParams = Object.assign({}, this.fetchParams);
    },
    delHandle() {},
    commitHandle() {},
    async getvehicleList() {
      let res = await vehicleConfiguration(0, { isUnlimited: 10041001 });
      this.topFilterList.find(item => item.fieldName === 'brandProductList').itemList = res.data;
    },
    createdFrom() {
      return [
        {
          type: 'INPUT_CASCADER',
          label: '车型选择',
          fieldName: 'brandProductList',
          placeholder: '请选择',
          options: { titles: ['品牌', '车系', '车型', '配置', '选装'] },
          itemList: []
        },
        {
          type: 'TEXT_AREA',
          label: 'VIN',
          fieldName: 'vin',
          placeholder: '请输入',
          maxlength: '',
          maxRows: 2
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },

        //         <multiuse-button size="mini" type="text" onClick={() => this.delHandle(props.row)}>
        //           删除
        //         </multiuse-button>
        //         <multiuse-button size="mini" type="text" onClick={() => this.commitHandle(props.row)}>
        //           提交
        //         </multiuse-button>
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 120,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button size="mini" type="text" onClick={() => this.renderHandle(props.row, 'edit')}>
                  编辑
                </multiuse-button>
                <multiuse-button size="mini" type="text" onClick={() => this.renderHandle(props.row, 'show')}>
                  明细
                </multiuse-button>
              </div>
            );
          }
        },
        {
          title: '申请单号',
          dataIndex: 'applyNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '品牌',
          dataIndex: 'brandName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车系',
          dataIndex: 'seriesName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车型',
          dataIndex: 'modelName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配置',
          dataIndex: 'packageName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '选装',
          dataIndex: 'optionName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '内饰',
          dataIndex: 'trimColor',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '外饰',
          dataIndex: 'colorName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品代码',
          dataIndex: 'productCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: 'VIN',
          dataIndex: 'vin',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '提报日期',
          dataIndex: 'applyDate',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd'
        }
      ];
    }
  }
};
</script>
